package com.su.volley;

import java.util.concurrent.PriorityBlockingQueue;

public class RequestQueue {

	private PriorityBlockingQueue<IRequest<?>> mWorkTasks;

	public RequestQueue() {
		mWorkTasks = new PriorityBlockingQueue<IRequest<?>>();
		mNetWorkDispaters = new NetWorkDispater[DEFAULT_POOLS_SIZE];
	}

	private NetWorkDispater[] mNetWorkDispaters;

	private final static int DEFAULT_POOLS_SIZE = 4;

	public <T> void start() {
		for (int i = 0; i < mNetWorkDispaters.length; i++) {
			NetWorkDispater netWorkDispater = new NetWorkDispater(this,
					mWorkTasks);
			mNetWorkDispaters[i] = netWorkDispater;
			netWorkDispater.start();
		}

	}

	public void add(IRequest<?> request) {
		mWorkTasks.add(request);
	}

	public void stop() {
		for (int i = 0; i < mNetWorkDispaters.length; i++) {
			mNetWorkDispaters[i].quit();
		}
	}

}
